CXXFLAGS=-I../include -Wall -O2 -g3 
LDFLAGS=-Wall -lpcre -lpcre++ -L../ -lhl7pp -L../
LD_LIBRARY_PATH=../

srcs=$(wildcard *.cpp)
targets=$(shell ls *.cpp | sed -re 's/.cpp//g')
tests=$(shell ls *.cpp | sed -re 's/.cpp/test/g')

DEBUGFLAGS=-DDEBUG
tfile=../data/example_msg.hl7
tfile2=../data/adt_a04_13885_20090811203018

.EXPORT_ALL_VARIABLES: environ
.PHONY: clean environ

all: environ clean $(targets) $(tests)

hl7: hl7.cpp
	@echo [CXX] $@
	@$(CXX) $(CXXFLAGS) $(LDFLAGS) $? -o $@

util: util.cpp
	@echo [CXX] $?
	@$(CXX) $(CXXFLAGS) $(LDFLAGS) $? -o $@


# Running the tests
utiltest: util
	@echo [utiltest] ./$@
	@./$?

hl7test: hl7
	@echo [hl7test] ./$? $(tfile)
	@./$? $(tfile)

hl7mem: hl7
	@echo [memcheck] $@
	@valgrind --track-origins=yes --leak-check=full -v ./$? $(tfile)

utilmem: util
	@echo [memcheck] $@
	@valgrind --track-origins=yes --leak-check=full -v ./$? 

clean:
	@echo [clean]
	@-rm -f $(targets) core

environ:
	@echo fixing environ - make sure hl7lib has been built before running these tests!

tags:
	ln -s ../tags
